package com.example.sailscan_zxing_android;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.google.zxing.client.android.CaptureActivity;



public class MainActivity extends AppCompatActivity {
    Button Scan_Button;
    TextView Result_TextView;

    public static final int REQUEST_SCAN_QRCODE = 0X01;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Scan_Button=findViewById(R.id.scan_button);
        Result_TextView=findViewById(R.id.result_textview);

        Scan_Button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent =new Intent(MainActivity.this, CaptureActivity.class);
                startActivityForResult(intent,REQUEST_SCAN_QRCODE);

            }
        });


    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (requestCode){
            case REQUEST_SCAN_QRCODE:
                Bundle result_data=data.getExtras();
                String result_String=result_data.getString("Result");
                Result_TextView.setText(result_String);
        }
    }
}